package com.demo.java.OD151_200.OD162;

import java.util.Scanner;

/**
 * @author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @des： 【最优资源分配】问题
 * @url： https://blog.csdn.net/weixin_43970743/article/details/145765779
 */
public class OdMain {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 读取板卡的总容量和芯片数量
        int board_capacity = scanner.nextInt();
        int number_of_chips = scanner.nextInt();
        scanner.nextLine(); // 读取换行符
        String chip_configurations = scanner.nextLine();

        // 用数组记录每个芯片的已分配容量
        int[] chip_capacity = new int[number_of_chips];
        int configuration_capacity;

        // 处理每个芯片的配置
        for (int i = 0; i < chip_configurations.length(); i++) {
            char chip_type = chip_configurations.charAt(i);
            switch (chip_type) {
                case 'A':
                    configuration_capacity = 1;
                    break;
                case 'B':
                    configuration_capacity = 2;
                    break;
                default:
                    configuration_capacity = 8;
                    break;
            }
            // 尝试将配置分配到芯片中
            for (int j = 0; j < number_of_chips; j++) {
                int used_capacity = chip_capacity[j];
                if (board_capacity - used_capacity >= configuration_capacity) {
                    chip_capacity[j] += configuration_capacity;
                    break;
                }
            }
        }

        // 输出每个芯片的资源分配情况
        for (int i = 0; i < number_of_chips; i++) {
            StringBuilder chip_configuration = new StringBuilder();
            int used_capacity = chip_capacity[i];
            for (int j = 0; j < board_capacity; j++) {
                chip_configuration.append(j < used_capacity ? "1" : "0");
            }
            System.out.println(chip_configuration);
        }
    }
}